﻿#include "pch.h"
#include "WoJWT.h"
#include "jwtbase.h"

JWTVerifier WoJWTVerify(const CXTextA& issuer) {
	return std::make_shared<jwt::verifier<jwt::default_clock, jwt::traits::kazuho_picojson>>(
		jwt::verify().with_issuer(issuer.get()==nullptr?"": issuer.get())
	);
}


void WOJWTAllowAlgorithmHS256(JWTVerifier& verify,const CXTextA&key) {
	verify->allow_algorithm(jwt::algorithm::hs256(key.get()));
}
void WOJWTAllowAlgorithmHS384(JWTVerifier& verify, const CXTextA& key) {
	verify->allow_algorithm(jwt::algorithm::hs384(key.get()));
}
void WOJWTAllowAlgorithmHS512(JWTVerifier& verify, const CXTextA& key) {
	verify->allow_algorithm(jwt::algorithm::hs512(key.get()));
}

void WOJWTAllowAlgorithmPS256(JWTVerifier& verify, 
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password) {
	verify->allow_algorithm(jwt::algorithm::ps256(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmPS384(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::ps384(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmPS512(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::ps512(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}

void WOJWTAllowAlgorithmRS256(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password) {
	verify->allow_algorithm(jwt::algorithm::rs256(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmRS384(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::rs384(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmRS512(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::rs512(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}

void WOJWTAllowAlgorithmED25519(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::ed25519(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmED448(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::ed448(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmES256(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::es256(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmES256k(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::es256k(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}

void WOJWTAllowAlgorithmES384(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::es384(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
void WOJWTAllowAlgorithmES512(JWTVerifier& verify,
	const CXTextA& public_key,
	const CXTextA& public_key_password,
	const CXTextA& private_key,
	const CXTextA& private_key_password
) {
	verify->allow_algorithm(jwt::algorithm::es512(
		public_key.get(),
		private_key.get(),
		public_key_password.get(),
		private_key_password.get()
	));
}
